package com.khshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khshop.pojo.Menupriv;
import com.khshop.mapper.MenuprivMapper;
import com.khshop.service.MenuprivService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.khshop.vo.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 按钮权限 服务实现类
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Service
public class MenuprivServiceImpl extends ServiceImpl<MenuprivMapper, Menupriv> implements MenuprivService {

    @Autowired(required = false)
    MenuprivMapper menuprivMapper;

    //新增按钮权限
    public ServiceResult<Menupriv> addMenupriv(Menupriv menupriv){
        return ServiceResult.of(menuprivMapper.insert(menupriv)>0);

    }

    //修改按钮权限
    public ServiceResult<Menupriv> updateMenupriv(Menupriv menupriv){
        return ServiceResult.of(menuprivMapper.updateById(menupriv)>0);

    }

    //删除按钮权限
    public ServiceResult<Menupriv> delMenupriv(Integer id){
        return ServiceResult.of(menuprivMapper.deleteById(id)>0);

    }


    //查询按钮权限
    public ServiceResult<IPage<Menupriv>> searchMenupriv(Map<String,String> map, Integer page, Integer limit){
        QueryWrapper<Menupriv> queryWrapper = new QueryWrapper<>();
        queryWrapper.allEq(map);
        Page<Menupriv> iPage = new Page<Menupriv>(page, limit);
        IPage<Menupriv> orderIPage = menuprivMapper.selectPage(iPage, queryWrapper);
        return ServiceResult.of(orderIPage,orderIPage.getSize()>0);

    }
}
